package com.zisu.springcloud.controller;

import com.zisu.springcloud.entity.CommonResult;
import com.zisu.springcloud.entity.Payment;
import com.zisu.springcloud.service.PaymentFeignService;
import feign.Param;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Desc: ""
 * @Author: caixiang
 * @DATE: 2020/9/4 16:33
 */
@RestController
@Slf4j
public class OrderFeignController {
    //直接用 带Feign 的接口就行了，，不用去实现哪个接口，因为它 调用的 本来 就是微服务
//    @Resource
//    private PaymentFeignService paymentFeignService;
//
//    @GetMapping(value = "/consumer/payment/get/{id}")
//    public CommonResult<Payment> getPaymentById(@Param("id") Long id){
//        return paymentFeignService.get(id);
//    }

    @Resource
    private PaymentFeignService paymentFeignService;

    //参数一定要传对 不是@Param("id")，，不然拿到是null，然后传递给远程服务，就会报错404
    @GetMapping(value = "/consumer/payment/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id){
        return paymentFeignService.get(id);
    }

    @GetMapping(value = "/consumer/payment/feign/timeout")
    public String paymentFeignTimeout(){
        //openfeign-ribbon ,,客户端默认等待1s
        return paymentFeignService.paymentFeignTimeout();
    }
}
